<?php
defined('_JEXEC') or die('Restricted access');
$app = JFactory::getApplication();
$input = $app->input;
$action = $input->get('action');
$task = $input->get('task');
$itemid = $input->get('Itemid');
$items = $this->get('Items');
$this->pagination = $this->get('pagination');
$AppList =  $this->get('App');
$model = $this->getModel();
$funnel_id = (int) $input->get('funnel_id');
$Funnel = $model->getFunnel( $funnel_id);
$EventList = $this->get('Events');

?>

<?php if ($action == 'create'): //表单?>

<div style="padding-left: 20px;">
    <h2>Create Funnel Item</h2>
    <form method="post" class="J_ajaxFsorm" action="/index.php?option=com_console&Itemid=127&task=<?php echo $task; ?>&action=store">
        <input type="hidden" name="funnel_id" value="<?php echo  $funnel_id?>">
         <input type="hidden" name="position" value="0">
        <div class="form-group">
            <label for="">funnel name:  </label>
             <span><?php echo $Funnel->name; ?></span> 
        </div>
        <div class="form-group">
            <label for="exampleInputEmail1">set event</label>
            <select class="form-control" name="event_id">
           <?php foreach ($EventList as $key =>$event ): ?>
              <option value=<?php echo $event->event_id; ?>><?php echo $event->event_name; ?></option>
             <?php endforeach ?>
            </select>
        </div>
       
        <button type="submit" class="btn btn-default J_ajax_submit_btn">Create</button> <button  class="btn btn-primary  active" onclick="history.go(-1)">Back</button>
    </form>
</div>
<?php elseif ($action == 'edit'): //表单?>
<?php
$Item = $model->getItem( (int) $input->get('id'));
?>
<div style="padding-left: 20px;">
    <h2>Edit Event Funnel</h2>
    <form method="post" class="J_ajaxFsorm" action="/index.php?option=com_console&Itemid=127&task=<?php echo $task; ?>&action=update&funnel_id=<?php echo $funnel_id; ?>">
        <input type="hidden" name="id" value="<?php echo $Item->id;?>">
        <div class="form-group">
            <label for="">funnel name:  </label>
             <span><?php echo $Funnel->name; ?></span> 
        </div>
        <div class="form-group">
            <label for="exampleInputEmail1">set event</label>
            <select class="form-control" name="event_id">
           <?php foreach ($EventList as $key =>$event ): ?>
              <option value=<?php echo $event->event_id; ?> <?php if( $event->event_id ==$Funnel->id ): ?>selected <?php endif;?>><?php echo $event->event_name; ?></option>
             <?php endforeach ?>
            </select>
        </div>
        
        <button type="submit" class="btn btn-default J_ajax_submit_btn">Save</button> <button  class="btn btn-primary  active" onclick="history.go(-1)">Back</button>
    </form>
</div>

<?php else: //列表?>
<div style="padding-left: 20px;">
    <div class="row"> 
    <a href="/index.php?option=com_console&view=<?php echo strtolower($task); ?>&Itemid=127&task=<?php echo $task; ?>&action=create&funnel_id=<?php echo $funnel_id; ?>" 
    class="btn btn-primary  active" role="button">Create Item</a>  <a href="/index.php?option=com_console&view=eventfunnel&Itemid=127&task=EventFunnel" 
    class="btn btn-primary  active" role="button">Funnel List</a> 
<?php if ($items): ?>
    <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
    <div id="main" style="width: 900px;height:400px;">
<form action="<?php echo htmlspecialchars(JUri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm">
 <table class="table table-striped">
             <thead><tr>
            <th>funnel name</th>  <th>event_id </th>  <th>event_name </th> <th>Operate</th>
             </tr></thead>
             <tbody>
             <?php foreach ($items as $key => $item): ?>
              <tr>

             <td><?php echo $item->name ?></td> 
              <td><?php echo $item->event_id ?></td> 
            <td><?php echo $item->event_name ?></td> 
             
           <td><a  href="/index.php?option=com_console&view=<?php echo strtolower($task); ?>&Itemid=127&task=<?php echo $task; ?>&action=edit&id=<?php echo $item->id?>&funnel_id=<?php echo $item->funnel_id ?>">Edit</a> &nbsp;
           <a  class="layer_confirm" title="are you sure?" href="/index.php?option=com_console&Itemid=127&task=<?php echo $task; ?>&action=delete&id=<?php echo $item->id?>">Delete</a></td> 
           </tr>
               <?php endforeach ?>
               </tbody>
         </table>
  <?php // Add pagination links ?>
  
    <div class="pagination">

    
        <p class="counter pull-right">
          <?php echo $this->pagination->getPagesCounter(); ?>
        </p>

      <?php echo $this->pagination->getPagesLinks(); ?>
    </div>
    </form>
    </div>
  <?php else: ?>
    not find item
    <?php endif ?>
</div>

<?php endif;?>
